 <!--codemirror-text格式化-->
<template>
  <div class="execute-dialog" >

    <el-row>
      <el-col :span="4">
        jira项目
      </el-col>
      <el-col :span="20">
        {{projectConfig.jira_project}}
      </el-col>
    </el-row>
     <el-row>
       <el-col :span="4">
        jira组件名
      </el-col>
      <el-col :span="20">
        {{projectConfig.component}}
      </el-col>
        </el-row>
    <el-row>
       <el-col :span="4">
        版本正则
      </el-col>
      <el-col :span="20">
        {{projectConfig.version_pattern}}
      </el-col>
        </el-row>

     <el-row>
       <el-col :span="4">
        项目PM
      </el-col>
      <el-col :span="20">
        <p v-for="item in projectConfig.pm">
          {{item}}
        </p>
      </el-col>
        </el-row>
     <el-row>
       <el-col :span="4">
        项目leader
      </el-col>
      <el-col :span="20">
        <p v-for="item in projectConfig.leaders">
          {{item}}
        </p>
      </el-col>
        </el-row>
     <el-row>
       <el-col :span="4">
        发版周期
      </el-col>
      <el-col :span="20">
        {{projectConfig.release_weeks}}
      </el-col>
        </el-row>


     <el-row>
        <el-col :span="4">
          git地址
      </el-col>
      <el-col :span="20">
         <p v-for="item in projectConfig.git_info_list">
           {{item["type"]}}-{{item["modulename"]}}-<a target="_blank" :href='item["git_url"]'>{{item["git_url"]}}</a>
        </p>
      </el-col>
    </el-row>
     <el-row>
        <el-col :span="4">
          checklist目录
      </el-col>
      <el-col :span="20">
        {{projectConfig.gdrive_dir}}
      </el-col>
    </el-row>

     <el-row>
        <el-col :span="4">
          版本号
      </el-col>
      <el-col :span="10">
       <el-input v-model="version"></el-input>
      </el-col>
       <el-col :span="10">
         <el-button type="primary" @click="getUnreleaseVersion">获取版本号</el-button>
      </el-col>
    </el-row>

    <el-row>
        <el-col :span="24" >
          提示：{{message}}
      </el-col>
    </el-row>
    <el-row v-loading="loading">
        <el-col :span="12" align="center">
          <el-button type="primary" @click="execute">执行</el-button>
      </el-col>
      <el-col :span="12" align="center">
        <el-button @click="cancel">取消</el-button>
      </el-col>
    </el-row>

  </div>
</template>

<script>


  import {api, getRequest, postRequest} from "@/api/commit";

  export default {
  name: 'ExecuteDialog',
  /* eslint-disable vue/require-prop-types */
  props: ['task_id'],
  data () {
    return {
      projectConfig: {},
      version:"",
      message:"",
      loading:false
    }
  },
  methods: {
     init_data() {
       getRequest(api['get_project_config'],{id:this.task_id}).then((res) => {
         res = res.resultReturn
         this.projectConfig= res
       }, (error) => {
         console.info(error)
       })
     },
    getUnreleaseVersion(){
       getRequest(api['get_unrelease_version'],{id:this.task_id}).then((res) => {
         res = res.resultReturn
         this.message= res.message
         this.version= res.data
       }, (error) => {
         console.info(error)
       })
    },
    toTaskInstanceListView: function(id){
        this.$router.push({
            path: '/TaskInstanceListView'
          })
        },
    cancel(){
       this.$emit("closeExecuteDialog")
    },
    execute(){
       this.loading=true
       postRequest(api['task_execute'],{id:this.task_id,version:this.version}).then((res) => {
         res = res.resultReturn
         this.loading=false
         if(res.status!==0){
            this.message= res.message
         }else {
           // 跳转到发布列表
           this.toTaskInstanceListView()
         }

       }, (error) => {
         this.loading=false
         console.info(error)
       })
    }
  },
    // 不用 watch
  created() {
    this.init_data()
  }
    ,
  // mounted () {
  //   this.init_data()
  // }
}
</script>

<style scoped>
.text-editor {
  height: 100%;
  position: relative;
}
.text-editor >>> .CodeMirror {
  height: auto;
  min-height: 180px;
}
.text-editor >>> .CodeMirror-scroll {
  min-height: 180px;
}
.text-editor >>> .cm-s-rubyblue span.cm-string {
  color: #f08047;
}
</style>
